#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>

void *tfn(void *arg){
		printf("thread: pid = %d, tid=%ld\n",getpid(),pthread_self());
		sleep(1);
	return NULL;
}



int main(int argc, char *argv[]){
	pthread_t tid;
	int ret = pthread_create(&tid,NULL,tfn,NULL);
	if (ret != 0){
		fprintf(stderr,"pthread_create error %s\n",strerror(ret));
		exit(1);
	}
	ret = pthread_detach(tid);//设置子线程为分离态，主线程结束后，自动回收
       if(ret !=0){
		fprintf(stderr,"pthread_detach error %s\n",strerror(ret));
		exit(1);
        }
	
	ret = pthread_join(tid,NULL);

	if(ret !=0){
		fprintf(stderr,"pthread_join error %s\n",strerror(ret));
		exit(1);
        }

	printf("main:pid = %d, tid = %lu\n",getpid(),pthread_self());

	pthread_exit((void*)0);
	
}


